﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Employee.master" AutoEventWireup="true"
    CodeFile="ViewStock.aspx.cs" Inherits="ViewStock" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
        function onlyNumbers(evt) {
            var e = event || evt; // for trans-browser compatibility
            var charCode = e.which || e.keyCode;

            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

            return true;

        }
        var TotalChkBx;
        var Counter;

        window.onload = function() {
            TotalChkBx = parseInt('<%= this.gvViewStock.Rows.Count %>');
            Counter = 0;
        }

        function SelectAll(CheckBox) {
            var TargetBaseControl = document.getElementById('<%= this.gvViewStock.ClientID %>');
            var TargetChildControl = "chkselect";
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for (var n = 0; n < Inputs.length; ++n)
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
            Counter = CheckBox.checked ? TotalChkBx : 0;
        }

        function ChildClick(CheckBox, HCheckBox) {
            var HeaderCheckBox = document.getElementById(HCheckBox);
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }         
    
    </script>

    <table width="100%">
        <tr>
            <td valign="middle" class="header">
                View Stock
            </td>
        </tr>
    </table>
    <br />
    <div height="34px" width="487px">
        <b>Search Deliverable:</b>
        <asp:TextBox ID="txtDeliverableSearch" runat="server" ValidationGroup="GroupSearch" onkeypress="return onlyNumbers();"></asp:TextBox>
           
        <asp:Button ID="btnSearch" runat="server" Text="Search" Height="26px" 
            ValidationGroup="GroupSearch" onclick="btnSearch_Click" /><br />
        <asp:RequiredFieldValidator ID="valSearch" runat="server" ErrorMessage="You must type what you need to search" ValidationGroup="GroupSearch"
            ControlToValidate="txtDeliverableSearch"></asp:RequiredFieldValidator>
            <br />
        <b>
            <asp:RadioButton ID="rdDeliveryNumber" runat="server" Checked="True" GroupName="GroupSearch"
                Text="Deliverable ID" />&nbsp;</b> <b>
                    <asp:RadioButton ID="rdPinCode" runat="server" GroupName="GroupSearch" Text="Pin Code" /></b>
    </div>
    <br />
    <asp:Label ID="lblMessage" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
    <br />
    <asp:GridView ID="gvViewStock" runat="server" AutoGenerateColumns="False" DataKeyNames="DeliverableID"
        HeaderStyle-CssClass="smallheader" HeaderStyle-BackColor="#a9c0f2" BorderColor="#556CB0"
        GridLines="Vertical" Width="100%" DataSourceID="ObjectDataSourceViewStock">
        <Columns>
            <asp:TemplateField HeaderText="ID" SortExpression="DeliverableID" ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                  <b>  <asp:Label ID="lblDeliverableID" runat="server" Text='<%# Bind("DeliverableID") %>'></asp:Label></b>
                </ItemTemplate>
                
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                
            </asp:TemplateField>
            <asp:TemplateField HeaderText="From Stock" SortExpression="FromStock">
                <ItemTemplate>
                    <asp:Label ID="lblFromStock" runat="server" Text='<%# Bind("FromStock") %>'></asp:Label>
                </ItemTemplate>
               
            </asp:TemplateField>
            <asp:TemplateField HeaderText="To Stock" SortExpression="ToStock">
                <ItemTemplate>
                    <asp:Label ID="lblToStock" runat="server" Text='<%# Bind("ToStock") %>'></asp:Label>
                </ItemTemplate>
              
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Received Date" SortExpression="ReceivedDate">
                <ItemTemplate>
                    <asp:Label ID="lblReceivedDate" runat="server" Text='<%# Bind("ReceivedDate") %>'></asp:Label>
                </ItemTemplate>
             
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Sent Date" SortExpression="SentDate">
                <ItemTemplate>
                    <asp:Label ID="lblSentDate" runat="server" Text='<%# Bind("SentDate") %>'></asp:Label>
                </ItemTemplate>
               
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Status" SortExpression="Status">
                <ItemTemplate>
                    <asp:CheckBox ID="lblStatus" runat="server" Checked='<%# Bind("Status") %>' Enabled="false" />
                </ItemTemplate>
               
            </asp:TemplateField>
            <asp:HyperLinkField DataNavigateUrlFields="DeliverableID" DataNavigateUrlFormatString="~/Pages_Employee/ManageStocks/EditStock.aspx?DeliverableID={0}"
                HeaderText="Edit" Text="Edit" />
            <asp:TemplateField ItemStyle-Width="20">
                <HeaderTemplate>
                    <asp:CheckBox ID="chkheader" runat="server" onclick="javascript:SelectAll(this);" />
                </HeaderTemplate>
                <ItemTemplate>
                    <div align="center">
                        <asp:CheckBox ID="chkselect" runat="server" 
                            ToolTip='<%# Eval("DeliverableID") %>' />
                    </div>
                </ItemTemplate>
                <ItemStyle Width="20px"></ItemStyle>
            </asp:TemplateField>
        </Columns>
        <HeaderStyle HorizontalAlign="Center" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSourceViewStock" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="ViewStock" TypeName="DALStock">
        <SelectParameters>
            <asp:SessionParameter Name="StockPinCode" SessionField="PinCode" 
                Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <br />
    <div align="left">
        <asp:Button ID="btnAddDeliverable" runat="server" Text="Add new deliverable" 
            onclick="btnAddDeliverable_Click" />
        <asp:Button ID="btnDeleteDeliverable" runat="server" 
            Text="Delete selected deliverables" onclick="btnDeleteDeliverable_Click" 
            onclientclick="return confirm(&quot;Are you sure you want to delete selected branch?&quot;);" />
    </div>
</asp:Content>
